import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button, Form, DatePicker, Card, Table } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import dataEditCreate from '../../addons/DataEdit'
import * as datetime from '../../../utils/datetime'
import * as compDiviService from '../../../services/AccountDivi';
const ButtonGroup=Button.Group
class SckhzhsyForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dateValue: null,
      loading1:false,
      loading2:false
    }
  }
  showDiviHandler() {
    this.setState({loading1:true})  
    let dateString = this.state.dateValue;
    compDiviService.Scdgzhsysj({ dateString}
    ).then(function (data) {
      if (data === 'OK') {
        message.success('数据处理成功！')
        this.setState({loading1:false})  
      } else {
        message.error('数据处理失败！' + data)
        return;
      }
    }.bind(this)).catch(function (ex) {
      console.log('请求出错', ex)
    });
    
  }
  showDiviHandler2() {
    this.setState({loading2:true})  
    let dateString = this.state.dateValue;
    compDiviService.Sczxzhsysj({ dateString}
    ).then(function (data) {
      if (data === 'OK') {
        message.success('数据处理成功！')
        this.setState({loading2:false})  
      } else {
        message.error('数据处理失败！' + data)
        return;
      }
    }.bind(this)).catch(function (ex) {
      console.log('请求出错', ex)
    });
    
  }
  SelDate(date, dateString) {
    this.state.dateValue = dateString;
  }
  render() {
    let { showEdit, record, offsetWidth, offsetHeight, permID, popedomTypes } = this.props
    let x = (offsetWidth / 2 - 10) / 2
    let y = offsetHeight - 115
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <Card style={{ height: y }} bodyStyle={{ padding: 0 }}>
          <div style={{ marginLeft: x, marginLeft:"25%", color: 'red' }}>
            <br /><br /><br /><br />
            注意：<br />
            1、如果修改了综合收益的主客户和关联客户或重新设置了综合收益目标，并<br />
            想及时看到变化数据，需调此功能(PS：系统每天会自动处理！)<br />
            2、若不选择追溯日期，则根据当前数据日期生成完成情况；若选择追溯日期<br />
            则根据所选择的时间生成综合收益的完成情况；若综合收益目标设置的起始日<br />
            期大于当前的数据日期，则该数据不会生成完成情况数据。<br />
            3、此功能执行需要几分钟，请耐心等待！<br />
            <br />
            <div>
              <span style={{ color: 'black', height: 50,marginLeft: "1%"}}>
                追溯日期:
              </span>
              <span>
                <DatePicker onChange={this.SelDate.bind(this)} style={{ 'vertical-align': 'bottom' }} />
              </span>
              <br />
              <br />
              <span style={{ marginLeft: "1%" }}>
              <ButtonGroup>
                <Button loading={this.state.loading1} onClick={this.showDiviHandler.bind(this)} type="primary">处理对公客户综合收益修改</Button>
                &nbsp;&nbsp;
                <Button loading={this.state.loading2} onClick={this.showDiviHandler2.bind(this)} type="primary">处理中小客户综合收益修改</Button>
              </ButtonGroup>
              </span>
            </div>
          </div>
        </Card>
      </div>
    )
  }
}

function mapStateToProps(state) {
  const { offsetHeight, userID, orgID, pOrgID, popedomTypes, offsetWidth, odsDate } = state.menus
  return {
    userID,
    orgID,
    pOrgID,
    popedomTypes,
    offsetHeight,
    offsetWidth,
    odsDate
  }
}
SckhzhsyForm = connect(mapStateToProps)(SckhzhsyForm)
export default SckhzhsyForm;

let render = (props) => React.createElement(SckhzhsyForm, props);
let f = new Factory()
f.set("SckhzhsyForm", render)
